package solutions.leetcode.easy;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/rotate-image/">48. 旋转图像</a>
 */
public class Solution48 {

    public void rotate(int[][] matrix) {
        int floor = 1;
        int size = matrix.length;
        while (floor <= size / 2) {
            int x = floor - 1, p = floor - 1, tmp = 0;
            while (p < size - x - 1) {
                tmp = matrix[x][p];
                matrix[x][p] = matrix[size - 1 - p][x];
                matrix[size - 1 - p][x] = matrix[size - 1 - x][size - 1 - p];
                matrix[size - 1 - x][size - 1 - p] = matrix[p][size - 1 - x];
                matrix[p][size - 1 - x] = tmp;
                p++;
            }
            floor++;
        }
    }

    public static void main(String[] args) {
        Solution48 solution = new Solution48();
        int[][] matrix = new int[][] {
                new int[] {1,2,3},{4,5,6},{7,8,9}
        };
        solution.rotate(matrix);
        System.out.println("ok");
    }
}
